<?php

function banner($type=null)
{
    $type = strtolower($type);
    $home=$register=$productlist=$contactus='';
    $home_act=$register_act=$productlist_act=$contactus_act='onmouseover="this.className=\'menu_over\'" onmouseout="this.className=\'menu_out\'"';
    if($type=='home'){
        $home = 'class="menu_over"';
        $home_act='';
    }else if($type=='register'){
        $register = 'class="menu_over"';
        $register_act = '';
    }else if($type=='product'){
        $productlist = 'class="menu_over"';
        $productlist_act = '';
    }else if($type=='home'){
        $contactus = 'class="menu_over"';
        $contactus_act = '';
    }else{
        $home_act=$register_act=$productlist_act=$contactus_act='';
    }
    
    echo '<table cellspacing="0" cellpadding="0" border="0" width="100%">
            <tr>
                <td style="width: 50%; color: #fff; font-weight: 150px;"><h1>ONLINE PC</h1></td>
                <td class="header">';

				if(@$_SESSION['member_username']=='' || $_SESSION['auth']!=1 || empty($_SESSION['member_id'])){

                    echo '<table cellspacing="0" cellpadding="0" border="0">
                        <tr>
                            <td '.$home.' '.$home_act.'  style="width: 112px; height: 34px; text-align: center;"><a href="index.php">Home</a></td>
                            <td '.$productlist.' '.$productlist_act.' style="width: 112px; text-align: center;"><a href="productlist.php">Product List</a></td>
							<td '.$register.' '.$register_act.' style="width: 112px; text-align: center;"><a href="register.php">Register</a></td>
                        ';

				}
				else{

					echo '<table cellspacing="0" cellpadding="0" border="0">
                        <tr>
                            <td '.$home.' '.$home_act.'  style="width: 112px; height: 34px; text-align: center;"><a href="index.php">Home</a></td>
                            <td '.$productlist.' '.$productlist_act.' style="width: 112px; text-align: center;"><a href="productlist.php">Product List</a></td>
                            
                        ';
				
				}
				
				echo
				'
				
				</tr>
				</table>
				';
				
				
                echo '</td>
            </tr>
        </table>';

}

function footer(){
    echo '<table cellspacing="0" cellpadding="0" border="0" width="100%"><tr><td style="background: transparent url(\'images/footer.png\') repeat-x; height: 40px;"><center><p>Copyright &copy; 2011. OnlinePC Site All Rights Reversed.</p></center></td></tr></table>';
}


function login(){
    $html_str = '';
    if(@$_SESSION['member_username']=='' || $_SESSION['auth']!=1 || empty($_SESSION['member_id'])){
        $html_str .= '<table cellspacing="0" cellpadding="0" border="0" width="100%" class="menu_link">';
        $html_str .= '<tr>';
        $html_str .= '<td width="300"><form method="post">
            <input type="text" class="rounded_corner" name="txtusername" id="txtusername" title="username" style="width: 100px;" />
            <input type="password" class="rounded_corner" name="txtpassword" id="txtpassword" title="usernamepas" style="width: 100px;" />
            <input type="button" class="rounded_corner" value="Login" id="btnlogin" name="btnlogin" style="width: 60px; cursor:pointer;" />
        </form>';
        $html_str .= '</td>';
        $html_str .= '<form action="productlist.php"><td width="50%" align="right"><input type="text" name="s" id="s" value="'.@$_GET['s'].'" class="rounded_corner" /> <input type="submit" value="Search" class="rounded_corner" style="cursor:pointer;"/></form></td>';
        $html_str .= '</tr>';
        $html_str .= '</table>';
    }else{
        $html_str  = '<table cellspacing="0" cellpadding="0" border="0" width="100%" class="menu_link">';
        $html_str .= '<tr>';        
        $html_str .= '<td><a href="profile.php">Profile</a>&nbsp;&nbsp;|&nbsp;&nbsp;</td>';
        $html_str .= '<td><a href="password.php">Change_Password</a>&nbsp;&nbsp;|&nbsp;&nbsp;</td>';
        $html_str .= '<td><a href="upload.php">Upload_Product</a>&nbsp;&nbsp;|&nbsp;&nbsp;</td>';
        $html_str .= '<td><a href="myproduct.php">My_Product</a>&nbsp;&nbsp;|&nbsp;&nbsp;</td>';
        $html_str .= '<td><a href="logout.php">Logout</a>(<strong>'.$_SESSION['member_username'].'</strong>)</td>';
        $html_str .= '<form action="productlist.php"><td width="50%" align="right"><input type="text" name="s" id="s" value="'.@$_GET['s'].'" class="rounded_corner" /> <input type="submit" value="Search" class="rounded_corner" style="cursor:pointer;"/></form></td>';
        $html_str .= '</tr>';
        $html_str .= '</table>';
    }
    echo $html_str;
}

function leftMenu($db)
{
    $html_str = '';
    $html_str .= '<table cellpadding="0" cellspacing="0" border="0" width="80%" style="margin-left: auto; margin-right: auto;">
                    <tr><td height="35"><h3>Categories</h3></td></tr>
                    <tr><td style="height: 1px; background: #fff;"></td></tr>
                    <tr><td style="height: 1px; background: #DFDDDD;"></td></tr>
                    <tr><td valign="top"><ul id="menu">';

    $query = $db->query('SELECT * FROM category ORDER BY category_id');

    while($row = $db->fetch($query)){
        
        $query2 = $db->query('SELECT * FROM subcategory WHERE category_id='.$row['category_id'].' ORDER BY subcategory_id');

        $count = $db->count($query2);
        if($count>0){
            $html_str .= '<li><a href="#">'.$row['category_name'].'</a>';
        }else{
            $html_str .= '<li><a href="productlist.php?cat='.$row['category_id'].'">'.$row['category_name'].'</a>';
			
        }

        $html_str .= '<ul>';

        while($row2 = $db->fetch($query2)){
            $html_str .='<li><a href="cat.php?c='.$row2['subcategory_id'].'">'.$row2['subcategory_name'].'</a></li>';
			
			
        }
        $html_str .= '</ul></li>';

    }
	$html_str .= '</ul></td></tr><tr><td style="height: 30px;"></td></tr></table>';

	echo $html_str;

}

?>
